/**
 * Created by danran on 2018/1/17.
 */
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#test1'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo1').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#up_sf'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo2').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText2');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#up_sf2'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo3').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText3');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#up_jb'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo_jb').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText3');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#up_jb2'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo_jb2').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText3');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#up_ye'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo_ye').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText_ye');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#up_ye2'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo_ye2').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText_ye2');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#up_ye3'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo_ye3').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText_ye3');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});
//协议书上传
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#up_xy'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo_xy').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText_xy');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#up_xy2'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo_xy2').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText_xy2');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#up_xy3'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo_xy3').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText_xy3');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#up_xy4'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo_xy4').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText_xy4');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#up_xy5'
        , url: '/upload/'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo_xy5').attr('src', result).prev().hide(); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText_xy5');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
});

//监听select
layui.use('form', function(){
    var form = layui.form;
//        监听执照类型选择
    var on_form=form.on('select(test)', function(data){
        if(data.value==2){
            $('.input_zhi').removeClass('hide')
        }else{
            $('.input_zhi').addClass('hide')
        }
    });
    var on_form2=form.on('select(zj_id)', function(data){
        if(data.value==2){
            $('.zj_class').removeClass('hide')
        }else{
            $('.zj_class').addClass('hide')
        }
    });
    var on_form3=form.on('select(select_zj)', function(data){

        if(data.value==2){
            $('.jb_input').removeClass('hide')
        }else{
            $('.jb_input').addClass('hide')
        }
    });
    //监听 账户账户
    var zh_class=form.on('select(zh_class)', function(data){
        if(data.value==3){
            $('.kh_sec').removeClass('hide')
        }else{
            $('.kh_sec').addClass('hide')
        }
    });
    var zh_class_zh=form.on('select(kh_zh)', function(data){
        if(data.value==2){
            $('.fill_zh').removeClass('hide')
        }else{
            $('.fill_zh').addClass('hide')
        }
    });
//        时间选择
    var on_check=form.on('checkbox(ye_time)', function(data){
        if(data.elem.checked==true){
            $(this).parent().prev().addClass('hide')
        }else{
            $(this).parent().prev().removeClass('hide')
        }
    });
    var on_switch = form.on('switch(switch_jb)', function(data){
        if(data.elem.checked==true){
            $(this).parent().parent().next().removeClass('hide')
        }else{
            $(this).parent().parent().next().addClass('hide')
        }

    });
    var on_switch1 = form.on('switch(ck_er)', function(data){
        if(data.elem.checked==true){
            $(this).parent().next().removeClass('hide')
        }else{
            $(this).parent().next().addClass('hide')
        }

    });



});

layui.use('laydate', function () {
    var laydate = layui.laydate;

    laydate.render({
        elem: '#time1'
    });
    laydate.render({
        elem: '#time2'
    });
    laydate.render({
        elem: '#time_zj'
    });
    laydate.render({
        elem: '#time_zj2'
    });
    laydate.render({
        elem: '#time_jb'
    });
    laydate.render({
        elem: '#time_jb2'
    });
});
//支付渠道加减
$(function () {
    var num = 0;
    $('.flm_plus').click(function () {
        num++;
        $(this).prev().text(num)
    })
    $('.flm_reduce').click(function () {
        if (num > 0) {
            num--;
        }

        $(this).next().text(num)
    })

})


